package com.zone.vehicle.superapp.view.common.base;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public abstract class BaseActivity<T extends HandledFragment> extends AppCompatActivity{

    private Map<String, T> pages = new LinkedHashMap<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initFragmentPages();
        setContentView();
    }

    protected abstract void initFragmentPages();

    protected abstract void setContentView();

    public Map<String, T> getPagesMap() {
        return pages;
    }

    public List<T> getPages() {
        return new ArrayList<>(pages.values());
    }

    public T getPage(int position){
        List<T> list = new ArrayList<>(pages.values());
        return list.get(position);
    }

    public T getPage(String pageName){
        return pages.get(pageName);
    }

    public void addPage(T fragment) {
        pages.put(fragment.getClass().getSimpleName(), fragment);
    }

}
